import fetch from "node-fetch";
export class fetchapi{
    private host="https://tea.ynmdiot.com"
    constructor(){

    }
    fetchGet(url?: string){
        const jwt_token=localStorage.getItem("jwt_token")
    
        return new Promise((resolve, reject) => {
            fetch(this.host+url,{
                headers: {
                    'Authorization':'Bearer '+ jwt_token,
                    'signature':jwt_token,
                }
            }).then(response=>{
                response.json().then(json=>{
                    resolve(json)
                })
            }).catch(error=>{
                reject({errcode:1})
                console.log(error)
            })
        })
    }
    fetchPost(url?: string,data?:any){
        const jwt_token=localStorage.getItem("jwt_token")
        return new Promise((resolve, reject) => {
            fetch(this.host+url,{
                body:JSON.stringify(data),
                method: 'POST', // *GET, POST, PUT, DELETE, etc.
                headers: {
                    'Authorization':'Bearer '+ jwt_token,
                    'signature':jwt_token,
                }
    
            }).then(response=>{
                response.json().then(json=>{
                    resolve(json)
                })
            }).catch(err=>{
                reject({errcode:1})
                console.log(err)
            })
        })
    }
}



